<template>
  <div style="background-color: white">
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
      ref="from"
      :list="formList"
      :cols="4"
      :formType="type"
      @formChange="changeHandle"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="工单信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
       ref="billfrom"
      :list="billList"
      :cols="4"
      :formType="type"
      @formChange="changeHandleBill"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="车辆信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
      ref="car"
      :list="carList"
      :cols="4"
      :formType="type"
      @formChange="changeHandleCar"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="投诉调查" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
      ref="query"
      :list="queryList"
      :cols="3"
      :formType="type"
      @formChange="changeHandlequery"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="处理明细" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
     ref="table"
     height="auto"
     :isColumnFilter="false"
     :isPagination="false"
     :isToperInfo="false"
     :columns="columns"
     :fetchapi="fetchApi"
     :params="fetchParams"
     :dataSource="complainDetailList"
     :isSelectColumn="false"
     columnsRef="jzySeries"
     :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
    <BreakSpace label="结案信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
      ref="query"
      :list="casecloseList"
      :cols="3"
      :formType="type"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="审核意见" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel
      ref="advice"
      :list="caseList"
      :cols="2"
      :isSubmitBtn="false"
      labelWidth="110" />
    <BreakSpace label="历史审核记录" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table"
      height="auto"
      :isColumnFilter="false"
      :isPagination="false"
      :isToperInfo="false"
      :columns="columns1"
      :fetchapi="fetchApi1"
      :params="fetchParams1"
      :dataSource="arbitrationList"
      :isSelectColumn="false"
      columnsRef="jzySeries"
      :onColumnsChange="columns => this.columns1 = columns1"
    >
    </FilterTable>
    <BaseDialog
      :visible.sync="isarbitration"
      :title="'处理明细'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dealwithdetail :type="handleType" :rowData="formData" @close="closeArbitration" />
    </BaseDialog>
    <div class="dialogBottmView" >
      <el-button :loading="saveLoading"  @click="doarbitration(1)"  type="primary">通过</el-button>
      <el-button :loading="saveLoading" @click="doarbitration(2)"  type="primary">驳回</el-button>
      <el-button   @click="closeDialog"  type="primary">返回</el-button>
    </div>
  </div>
</template>

<script>
  import {getcomplaindetiallist,doarbitration,getarbitrationlist} from '@/api/customerService/complaint/complaintbill/index.js';
  import {
    complaintSerious,
    SySubtype,
    complaintGender,
    shtype,
    complaintType,
    status,
    sjtype,
    complaintOrigin, jaStatus, isFeedback
  } from '../complaintbill/complaint';
  import moment from 'moment';
  import { getFileGroup } from '@/api/partsmanage/common/file';
  import { dictionary } from '@/utils/dictMixin';
  import { region } from '@/api/cms-common/region';
  import dealwithdetail from './dealwithdetail';
    export default {
      mixins: [dictionary,region],
      name: "complaindetil",
      props: {
        type: {
          type: String,
          default: 'add'
        },
        rowData: {
          type: Object,
          default: () => ({})
        }
      },
      components: {
        dealwithdetail
      },
      data() {
        this.saveData=null;
        return{
          isarbitration:false,
          handleType:'',
          roNo:'',// 工单号
          roCreateDate:'',// 开单日期
          formData:{},
          saveLoading:false,
          showAddNew:true,
          fetchApi:this.getcomplaindetiallist,
          fetchApi1:this.getarbitrationlist,
          fetchParams:{},
          fetchParams1:{},
          complainDetailList:[],
          arbitrationList:[],
          columns: this.createTableColumns(),
          billList:this.createTopFilterList(2),
          formList: this.createTopFilterList(1),
          carList:this.createTopFilterList(3),
          queryList:this.createTopFilterList(4),
          caseList:this.createTopFilterList(5),
          casecloseList:this.createTopFilterList(6),
          columns1:this.arbitrationTableColumns(),
          dealerId:'', //经销商的id
          dealerCode:'', //经销商代码
          rono:'', //订单号
          ronoId:'',// 订单的ID
          vin:''
        };
      },
      created() {
        this.fetchParams.id=this.rowData.id
        this.init()
      },
      methods: {
        doarbitration(type){
          // 通过
          const base=this.$refs.advice.SUBMIT_FORM();
          if (type===1){
            this.rowData.jaStatus='G'
            if (base.auditopinion){
              Object.assign(this.rowData,base)
            }else{
              this.$notify.error({title: '提示信息',message:'审核意见不能为空'});
              return false
            }
          }else{
            // 驳回
            if (base.auditopinion){
              this.rowData.jaStatus='F'
              Object.assign(this.rowData,base)
            }else{
              this.$notify.error({title: '提示信息',message:'审核意见不能为空'});
              return false
            }
          }
          this.rowData.complaintDate =  moment(this.rowData.complaintDate).format('yyyy-MM-dd HH:mm:ss')
          this.saveLoading=true
          // 仲裁操作
          doarbitration(this.rowData).then(res=>{
            if (res.resultCode === 200) {
              this.$notify.success({title: '提示信息',message:'保存成功!'});
              // 重新加载
              this.closeDialog();
            }else {
              this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
              // 重新加载
              this.closeDialog();
            }
          })
        },
        getcomplaindetiallist(){
          getcomplaindetiallist({id:this.rowData.id}).then(res=>{
            this.complainDetailList=res.data.records
          })
        },
        // 获取审核历史列表
        getarbitrationlist(){
          getarbitrationlist({id:this.rowData.id}).then(res=>{
            this.arbitrationList=res.data.records
          })
        },
        // 审批历史列表
        arbitrationTableColumns(){
          return [
            {
              title: '序号',
              dataIndex: 'index',
              width: 70,
              sorter: true,
              render: props => {
                return <span>{props.row.index + 1}</span>;
              }
            },
            {
              title: '审核部门',
              dataIndex: 'complainBranch',
              sorter: true,
            },
            {
              title: '审核人',
              dataIndex: 'complainName',
              sorter: true,
            },
            {
              title: '审核状态',
              dataIndex: 'complainStatus',
              sorter: true,
              dictItems: shtype
            },
            {
              title: '审核时间',
              dataIndex: 'complainTime',
              dateFormat:'yyyy-MM-dd HH:mm:ss',
              sorter: true,
            },
            {
              title: '驳回原因',
              dataIndex: 'rejectReason',
              sorter: true,
            },
            {
              title: '通过原因',
              dataIndex: 'adoptReason',
              sorter: true,
            }
          ]
        },
        // 处理明细
        closeArbitration(){
          this.isarbitration=false
        },
        dialogedit(row,type){
          this.handleType = type
          this.formData = row;
          this.isarbitration=true
        },
        //  处理明细列表
        createTableColumns(){
          return [
            {
              title: '操作',
              dataIndex: 'column-action',
              width: 60,
              fixed: 'left',
              render: (props) => {
                return (
                  <div>
                    <el-button size="mini" type="text" onClick={() => this.dialogedit(props.row,'show')}>
                      明细
                    </el-button>
                  </div>
                );
              }
            },
            {
              title: '序号',
              dataIndex: 'index',
              width: 60,
              render: props => {
                return <span>{props.row.index + 1}</span>;
              }
            },
            {
              title: '处理时间',
              dataIndex: 'handleTime',
              dateFormat:'yyyy-MM-dd HH:mm:ss',
            },
            {
              title: '处理人',
              dataIndex: 'handleBy',
            },
            {
              title: '处理人联系方式',
              dataIndex: 'phone',
            },
            {
              title: '处理结果',
              dataIndex: 'content',
            },
            {
              title: '备注',
              dataIndex: 'remarks',
            }
          ]
        },
        //返回操作
        closeDialog() {
          this.saveLoading=false
          this.$emit('close', { visible: false });
        },
        // 初始化列表带过来的一行数据
        init(){
          this.formList.forEach(x => {
            x.initialValue = this.rowData[x.fieldName];
          });
          this.queryList.forEach(x => {
            x.initialValue = this.rowData[x.fieldName];
          });
          this.billList.forEach(x => {
            x.initialValue = this.rowData[x.fieldName];
          });
          this.carList.forEach(x => {
            x.initialValue = this.rowData[x.fieldName];
          });
          this.carList.forEach(x => {
            if (x.fieldName==='ownerProperty'){
              x.initialValue= this.createDictText( this.rowData[x.fieldName], '8011')
            }else{
              x.initialValue = this.rowData[x.fieldName];
            }
          });
          this.casecloseList.forEach(x => {
            x.initialValue = this.rowData[x.fieldName];
          });
          getFileGroup({ "xtdjid": this.rowData.id, "xtfjlx": "6" }).then(response => {
            var fileList = response.data.records
            this.casecloseList.forEach(x => {
              if (x.fieldName === 'wayFiles') {
                x.initialValue = fileList
              }
            })
          })
        },
        createTopFilterList(type) {
          if (type===1){
            return [{//2
              type: 'INPUT',
              label: '投诉单编号',
              fieldName: 'complaintNo',
              initialValue:'',
              disabled:true
            },
              {//3
                type: 'INPUT',
                label: '投诉人姓名',
                fieldName: 'complaintName',
                initialValue: '',
                placeholder: '请输入',
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//3
                type: 'SELECT',
                label: '投诉人性别',
                fieldName: 'complaintGender',
                initialValue: '',
                placeholder: '',
                itemList:complaintGender,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//14
                type: 'INPUT',
                label: '投诉人电话',
                fieldName: 'complaintPhone',
                placeholder: '请输入',
                initialValue: '',
                maxlength:11,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'blur'
                  },
                  {
                    pattern: /^1(3|4|5|6|7|8|9)\d{9}$/,
                    message: '请填写正确的手机格式',
                    trigger: 'blur'
                  }
                ]
              },
              {//3
                type: 'SELECT',
                label: '投诉类型',
                fieldName: 'complaintType',
                initialValue: '',
                placeholder: '',
                itemList:complaintType,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//3
                type: 'SELECT',
                label: '投诉子类',
                fieldName: 'complaintSubtype',
                initialValue: '',
                placeholder: '',
                itemList:SySubtype,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//3
                type: 'DATE',
                label: '投诉日期',
                fieldName: 'complaintDate',
                initialValue: '',
                placeholder: '',
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//3
                type: 'SELECT',
                label: '处理状态',
                fieldName: 'status',
                initialValue: '',
                placeholder: '',
                itemList:status,
                disabled: true
              },
              {
                type: 'INPUT',
                label: '接待员',
                fieldName: 'receptionist',
                initialValue: '',
                disabled:true
              },
              {//3
                type: 'SELECT',
                label: '数据来源',
                fieldName: 'type',
                initialValue: '',
                placeholder: '',
                itemList:sjtype,
                disabled: true,
              },
              {//3
                type: 'SELECT',
                label: '投诉来源',
                fieldName: 'complaintOrigin',
                initialValue: '',
                placeholder: '',
                itemList:complaintOrigin,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {//3
                type: 'SELECT',
                label: '投诉等级',
                fieldName: 'complaintSerious',
                initialValue: '',
                placeholder: '',
                itemList:complaintSerious,
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'change'
                  }
                ]
              },
              {
                type: 'INPUT',
                label: '被投诉部门',
                fieldName: 'department',
                initialValue:'',
              },
              {
                type: 'INPUT',
                label: '被投诉员工',
                fieldName: 'beComplainTemp',
                initialValue:'',
              },
              {//22
                type: 'TEXT_AREA',
                label: '投诉单位',
                fieldName: 'complaintCorp',
                placeholder: '请输入',
                initialValue: '',
                maxlength:100,
                selfCols:4, //独占行数
              }
            ]
          }else if(type===2) {
            return[
              {//2
                type: 'INPUT',
                label: '工单号',
                fieldName: 'roNo',
                initialValue:'',
                readonly:true,
                unitRender: () => {
                  return (
                    <div>
                      <el-button icon="el-icon-search"></el-button>
                      <el-button slot="append" icon="el-icon-delete"></el-button>
                    </div>
                  );
                }
              },
              {//3
                type: 'DATE',
                label: '开单日期',
                fieldName: 'roCreateDate',
                initialValue: '',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '维修类型',
                fieldName: 'roType',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '服务顾问',
                fieldName: 'serviceAdvisor',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '送修人',
                fieldName: 'deliverer',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '送修人手机',
                fieldName: 'delivererMobile',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '送修人电话',
                fieldName: 'delivererPhone',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '责任技师',
                fieldName: 'chiefTechnician',
                initialValue:'',
                disabled:true
              }
            ]
          }else if (type===3){
            return[
              {//2
                type: 'INPUT',
                label: '车牌号',
                fieldName: 'license',
                initialValue:'',
                disabled:true,
                unitRender: () => {
                  return (
                    <div>
                      <el-button icon="el-icon-search" ></el-button>
                      <el-button slot="append" icon="el-icon-delete"></el-button>
                    </div>
                  );
                }
              },
              {//2
                type: 'INPUT',
                label: '车型',
                fieldName: 'modelName',
                initialValue:'',
                disabled:true,
              },
              {//3
                type: 'INPUT',
                label: 'VIN',
                fieldName: 'vin',
                initialValue: '',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '车主',
                fieldName: 'ownerName',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '车主性质',
                fieldName: 'ownerProperty',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'INPUT',
                label: '行驶里程',
                fieldName: 'currentMileage',
                initialValue:'',
                disabled:true
              },
              {//2
                type: 'DATE',
                label: '购车日期',
                fieldName: 'salesDate',
                format:'yyyy-MM-dd HH:mm:ss',
                initialValue:'',
                disabled:true
              }
            ]
          }else if (type===4){
            return [
              {//22
                type: 'TEXT_AREA',
                label: '投诉摘要',
                fieldName: 'complaintSummary',
                selfCols:2, //独占行数
                placeholder: '',
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: '必填',
                    trigger: 'blur'
                  }
                ]
              },
              {//22
                type: 'TEXT_AREA',
                label: '投诉原因',
                selfCols:2, //独占行数
                fieldName: 'complaintReason',
                placeholder: '',
                initialValue: ''
              },
              {//22
                type: 'TEXT_AREA',
                label: '备注信息',
                selfCols:2, //独占行数
                fieldName: 'remark',
                placeholder: '',
                initialValue: ''
              },
              {//22
                type: 'TEXT_AREA',
                label: '解决方案',
                selfCols:2, //独占行数
                fieldName: 'resolvent',
                placeholder: '',
                initialValue: ''
              }
            ]
          }else if(type===5) {
            return [
              {//22
                type: 'TEXT_AREA',
                label: '审核意见',
                fieldName: 'auditopinion',
                placeholder: '',
                initialValue: '',
              },
            ]
          }else{
            return [
              {//3
                type: 'SELECT',
                label: '结案状态',
                fieldName: 'jaStatus',
                initialValue: '',
                placeholder: '',
                itemList:jaStatus,
                disabled: true,
              },
              {//3
                type: 'SELECT',
                label: '是否可回访',
                fieldName: 'isFeedback',
                initialValue: '',
                placeholder: '',
                itemList:isFeedback,
                disabled: true,
              },
              {//22
                type: 'TEXT_AREA',
                label: '结案描述',
                fieldName: 'completeRemark',
                placeholder: '',
                selfCols:2,
                initialValue: ''
              },
              {//2
                type: 'TEXT_AREA',
                label: 'CC驳回原因',
                fieldName: 'ccRemark',
                selfCols:2,
                offsetRightCols:1,
                initialValue:'',
                disabled:true
              },
              {
                type: 'UPLOAD_FILE',
                label: '附件',
                fieldName: 'wayFiles',
                placeholder: '附件',
                disabled: true,
                initialValue: '',
                upload: {
                  actionUrl: '/api/file/oss/upload',
                  limit: 2,
                  tipText: '（支持：PDF、RAR、JPG格式）'
                }
              }
            ]
          }
        },
        changeHandle(val) {
          this.saveData=val;
        },
        changeHandleBill(val){
          console.info(val)
        },
        changeHandleCar(val){
          console.info(val)
        } ,
        changeHandlequery(val){
          console.info(val)
        }
      }
    }
</script>

<style scoped>

</style>
